/* 
目标：  路由初体验

  1. 安装依赖
  2. 引入依赖
*/

import React from 'react';
import './App.css';

// 2. 引入依赖
import { HashRouter, Route, NavLink, Link } from 'react-router-dom';


// 三个组件模拟 3 个页面
const Home = () => <div>首页</div>;
const User = () => <div>
  <h2>用户页</h2>
  <ul>
    <li><Link to="/user/1">列表内容1</Link></li>
    <li><Link to="/user/2">列表内容2</Link></li>
  </ul>
  {/* 动态路由，:id 其实就是个占位符 */}
  <Route path="/user/:id" component={UserDetail}></Route>
</div>;
const UserDetail = () => <div>
  xxx 列表详情页
</div>;
const About = () => <div>关于页</div>;

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <HashRouter>
          <nav className="nav">
            <NavLink exact to="/">切换首页</NavLink>
            <NavLink to="/user">用户列表页</NavLink>
            <NavLink to="/about">切换关于页</NavLink>
          </nav>
          <section className="section">
            <Route exact path="/" component={Home}></Route>
            <Route path="/user" component={User}></Route>
            <Route path="/about" component={About}></Route>
          </section>
        </HashRouter>
      </div>
    );
  }
}

export default App;
